//#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <stack>
#include <vector>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	vector<string> res;
	int t;
	cin >> t;
	for (int i = 0;i < t;i++) {
		int n;
		stack<uint64_t> s;
		cin >> n;
		for (int j = 0;j < n;j++) {
			string str;
			cin >> str;
			if (str == "push") {
				uint64_t tmp;
				cin >> tmp;
				s.push(tmp);
			}
			else if (str == "pop")
				if (s.size() == 0)
					res.push_back("Empty");
				else
					s.pop();
			else if (str == "query")
				if (s.size() == 0)
					res.push_back("Anguei!");
				else
					res.push_back(to_string(s.top()));
			else if (str == "size")
				res.push_back(to_string(s.size()));
		}
	}
	for (const auto& ans : res) {
		cout << ans << endl;
	}
	return 0;
}